<template>
  <view class="order">
    {{state.currentTab}}
    <AtTabs
      :swipeable="true"
      :current="state.currentTab"
      :tabList="state.tabList"
      :onClick="handleClick"
    >
      <AtTabsPane :current="state.currentTab" :index="0">
        <order-list :orderList="state.orderList" />
        <!-- <AtAccordion
          v-for="item in state.orderList"
          :key="item._id"
          :onClick="onClickTit"
          title='标题一'
          :open="item.isOpen"
        >
          <AtList :hasBorder="false">
            <AtListItem
              title='标题文字'
              thumb='https://img12.360buyimg.com/jdphoto/s72x72_jfs/t6160/14/2008729947/2754/7d512a86/595c3aeeNa89ddf71.png'
            />
            <AtListItem
              title='标题文字'
              note='描述信息'
              thumb='http://img12.360buyimg.com/jdphoto/s72x72_jfs/t10660/330/203667368/1672/801735d7/59c85643N31e68303.png'
            />
          </AtList>
        </AtAccordion> -->
      </AtTabsPane>
      <AtTabsPane :current="state.currentTab" :index="2">
        <order-list :orderList="state.orderList" />
      </AtTabsPane>
      <AtTabsPane :current="state.currentTab" :index="3">
        <order-list :orderList="state.orderList" />
      </AtTabsPane>
      <AtTabsPane :current="state.currentTab" :index="4">
        <order-list :orderList="state.orderList" />
      </AtTabsPane>
    </AtTabs>
  </view>
</template>

<script setup>
import { onBeforeMount, onMounted, reactive, ref, getCurrentInstance } from 'vue'
import Taro from "@tarojs/taro"
import orderList from "./orderList.vue"
import './order.scss'

import request from "../../utils/request";

const {ctx} = getCurrentInstance()

const state = reactive({
  currentTab: 0,
  tabList: [
    { title: '所有' },
    { title: '已受理' },
    { title: '进行中' },
    { title: '已完成' }
  ],
  orderList:[]
})

const handleClick = (val)=>{
  console.log(val);
  state.currentTab = val;
  getOrderList();
}

const onClickTit = (val)=>{
  console.log(val);
}

const getOrderList = async ()=>{
  let status = state.currentTab == 0 ? '' : state.currentTab
  let {data} = await request("/order/getList",'post',{status});
  state.orderList = data;
  state.orderList.forEach(item=>{
    item.isOpen = false
  })
  console.log(state.orderList);
}



onBeforeMount(()=>{
  getOrderList()
})


</script>
